package com.xxxx.seckill.test.rabbitMq.method;

import com.xxxx.seckill.test.rabbitMq.conf.MqNames;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SendMethod {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send01(Object obj) {
        log.info("normal queue : {}", obj);
        rabbitTemplate.convertAndSend(MqNames.NORMAL_QUEUE, obj);
    }

    public void send02(Object obj) throws InterruptedException {
        for (int i = 0; i < 50; i++) {
            rabbitTemplate.convertAndSend(MqNames.WORK_QUEUE, obj);
        }

    }

    //fanout
    public void send03(String s) {
        rabbitTemplate.convertAndSend(MqNames.EXCHANGE_FANOUT,"", s);
    }

    //direct
    public void send04(String s) {
        rabbitTemplate.convertAndSend(MqNames.EXCHANGE_DIRECT,s, s);
    }

    //Topic
    public void send05(String s) {
        rabbitTemplate.convertAndSend(MqNames.EXCHANGE_TOPIC,s, s);
    }

}
